<?php

namespace common\models\product;

use Yii;

/**
 * 这个模型基于表 "{{%product_stock_log}}" 生成。
 *
 * @property integer $id
 * @property integer $type
 * @property string $relate_sn
 * @property integer $product_id
 * @property integer $number
 * @property integer $stock
 * @property integer $add_time
 */
class ProductStockLog extends \common\models\AR {

    public $modelName = '库存变动日志';

    const TYPE_PURCHASE_IN = 1;  //采购进货
    const TYPE_PURCHASE_OUT = 2;  //采购退货
    const TYPE_CHANGE = 3;  //库存变动
    const TYPE_ORDER_IN = 4;  // 订单退货
    const TYPE_ORDER_OUT = 5;   //订单出库

    /**
     * @inheritdoc
     */
    public static function tableName() {
        return '{{%product_stock_log}}';
    }

    /**
     * @inheritdoc
     */
    public function rules() {
        return [
            [['type', 'relate_sn', 'product_id', 'number', 'stock'], 'required'],
            [['type', 'product_id', 'number', 'stock', 'add_time'], 'integer'],
            [['relate_sn'], 'string', 'max' => 20],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels() {
        return [
            'id' => 'ID',
            'type' => '变动类型',
            'relate_sn' => '单据编号',
            'product_id' => '货品ID',
            'number' => '货品变动数量',
            'stock' => '变动前的库存数',
            'add_time' => '添加时间',
        ];
    }

}
